package com.appwoo.txtws.activity;

import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;
import com.appwoo.txtws.adapter.ListViewCreator;
import com.appwoo.txtws.adapter.Page;
import com.appwoo.txtws.adapter.SimpleListAdapter;
import com.appwoo.txtws.app.App;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.AutoSoftInfo;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.DBHelper;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.LoadSourceForWeb;
import com.appwoo.txtws.service.RQNetLock;
import com.appwoo.txtws.wheel.widget.PageListView;
import com.appwoo.txtws.wheel.widget.PageListView.OnRefreshListener;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StudyYDActivity extends AppActivity
{
  public static Map<String, AsyncTask> downAT;
  public static List<AutoSoftInfo> eventsDown;
  public static Boolean isCancel;
  public static Boolean paused;
  private SimpleListAdapter<AutoSoftInfo> adapter;
  private String apkname = "";
  private String apkpath = "";
  private StateBean bean = new StateBean();
  private boolean blDataTask = false;
  private Button btnCurrent;
  private DBHelper dbhelper;
  private List<AutoSoftInfo> events;
  private Boolean isFoot = Boolean.valueOf(false);
  private int isHot = 1;
  private Boolean isSDCard = Boolean.valueOf(false);
  private PageListView lvList;
  private Page<AutoSoftInfo> page = new Page();
  private String typeID = "";

  private Boolean getIsCancelDown(String paramString)
  {
    Boolean localBoolean = Boolean.valueOf(true);
    if ((eventsDown != null) && (eventsDown.size() > 0));
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size())
        return localBoolean;
      if (paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
        return ((AutoSoftInfo)eventsDown.get(i)).getIsCancelDownload();
    }
  }

  private void initView()
  {
    this.isSDCard = Boolean.valueOf(Global.isSDCard());
    this.dbhelper = new DBHelper(this);
    this.lvList = ((PageListView)findViewById(2131492985));
    if (eventsDown == null)
      eventsDown = new ArrayList();
    if (downAT == null)
      downAT = new HashMap();
    this.adapter = new SimpleListAdapter(this.page.getEntries(), new ListViewCreator()
    {
      public View createView(final AutoSoftInfo paramAnonymousAutoSoftInfo, View paramAnonymousView, int paramAnonymousInt)
      {
        if (paramAnonymousView == null)
          paramAnonymousView = App.getLayoutInflater().inflate(2130903122, null);
        ((TextView)paramAnonymousView.findViewById(2131493160)).setText(paramAnonymousAutoSoftInfo.getSoftSize());
        ((TextView)paramAnonymousView.findViewById(2131493155)).setText(paramAnonymousAutoSoftInfo.getAsname());
        ((TextView)paramAnonymousView.findViewById(2131493158)).setText(paramAnonymousAutoSoftInfo.getDesc());
        ImageView localImageView = (ImageView)paramAnonymousView.findViewById(2131493154);
        Button localButton;
        int i;
        int j;
        int k;
        int m;
        if (paramAnonymousAutoSoftInfo.getIsRecd() == 1)
        {
          ((ImageView)paramAnonymousView.findViewById(2131493159)).setVisibility(0);
          StudyYDActivity.this.loadLogoImage(localImageView, paramAnonymousAutoSoftInfo.getAdicon(), StudyYDActivity.this.isSDCard);
          RatingBar localRatingBar = (RatingBar)paramAnonymousView.findViewById(2131493157);
          localRatingBar.setVisibility(0);
          localRatingBar.setRating(Float.parseFloat(paramAnonymousAutoSoftInfo.getHotMark()));
          localButton = (Button)paramAnonymousView.findViewById(2131493156);
          i = localButton.getPaddingLeft();
          j = localButton.getPaddingTop();
          k = localButton.getPaddingRight();
          m = localButton.getPaddingBottom();
          if (!Global.checkApkExist(StudyYDActivity.this, paramAnonymousAutoSoftInfo.getAspkg()))
            break label340;
          localButton.setText(StudyYDActivity.this.getResources().getString(2131427501));
          localButton.setTextColor(StudyYDActivity.this.getResources().getColor(2131230724));
          localButton.setBackgroundDrawable(StudyYDActivity.this.getResources().getDrawable(2130837636));
          localButton.setEnabled(false);
        }
        while (true)
        {
          localButton.setPadding(i, j, k, m);
          final ProgressBar localProgressBar = (ProgressBar)paramAnonymousView.findViewById(2131493072);
          StudyYDActivity.this.setCurrentProgressBar(paramAnonymousAutoSoftInfo.getKeyID(), localProgressBar, localButton);
          localButton.setOnClickListener(new View.OnClickListener()
          {
            public void onClick(View paramAnonymous2View)
            {
              Button localButton = (Button)paramAnonymous2View;
              if ((!Global.isSDCard()) && (Global.getMemorySize() < 10 + 5 * (1 + StudyYDActivity.eventsDown.size())))
              {
                StudyYDActivity.this.alertMessage("手机空间不足，不能完成安装。");
                return;
              }
              if ((StudyYDActivity.eventsDown.size() >= 3) && ((localButton.getTag() == null) || ("".equals(localButton.getTag()))))
              {
                StudyYDActivity.this.alertMessage(StudyYDActivity.this.getString(2131428059));
                return;
              }
              if ((!new RQNetLock(StudyYDActivity.this).getNetCmd().equals("1")) && (StudyYDActivity.this.isNetworkAvailable(StudyYDActivity.this)))
              {
                if ("安装".equals(localButton.getText()))
                {
                  StudyYDActivity.this.apkpath = paramAnonymousAutoSoftInfo.getAddownloadurl();
                  StudyYDActivity.this.apkname = paramAnonymousAutoSoftInfo.getAspkg();
                  localButton.setTag(paramAnonymousAutoSoftInfo.getKeyID());
                  paramAnonymousAutoSoftInfo.setIsCancelDownload(Boolean.valueOf(false));
                  StudyYDActivity.eventsDown.add(paramAnonymousAutoSoftInfo);
                  localButton.setText("取消");
                  StudyYDActivity.this.dbhelper.insertSoftsMarket(StudyYDActivity.this.apkname);
                  localProgressBar.setVisibility(0);
                  StudyYDActivity.this.showView(localProgressBar, (Button)paramAnonymous2View);
                  return;
                }
                StudyYDActivity.this.setEventIsCancelDown(Boolean.valueOf(true), paramAnonymousAutoSoftInfo.getKeyID());
                localButton.setText("安装");
                localButton.setTag(null);
                localProgressBar.setProgress(0);
                localProgressBar.setVisibility(8);
                return;
              }
              StudyYDActivity.this.alertMessage("无网络，请稍候再试");
            }
          });
          paramAnonymousView.setOnClickListener(new View.OnClickListener()
          {
            public void onClick(View paramAnonymous2View)
            {
              Bundle localBundle = new Bundle();
              localBundle.putString("softName", paramAnonymousAutoSoftInfo.getAsname());
              localBundle.putString("apkname", paramAnonymousAutoSoftInfo.getAspkg());
              localBundle.putString("author", paramAnonymousAutoSoftInfo.getAuthor());
              localBundle.putString("hotMark", paramAnonymousAutoSoftInfo.getHotMark());
              localBundle.putString("softSize", paramAnonymousAutoSoftInfo.getSoftSize());
              localBundle.putString("softType", paramAnonymousAutoSoftInfo.getTypeName());
              localBundle.putString("updateTime", paramAnonymousAutoSoftInfo.getUpdateTime());
              localBundle.putString("downloadurl", paramAnonymousAutoSoftInfo.getAddownloadurl());
              localBundle.putString("icon", paramAnonymousAutoSoftInfo.getAdicon());
              localBundle.putString("keyid", paramAnonymousAutoSoftInfo.getKeyID());
              localBundle.putString("version", paramAnonymousAutoSoftInfo.getVersion());
              StudyYDActivity.this.IntentActivity(StudyYDActivity.this, SoftInfoActivity.class, localBundle);
            }
          });
          return paramAnonymousView;
          ((ImageView)paramAnonymousView.findViewById(2131493159)).setVisibility(8);
          break;
          label340: localButton.setText(StudyYDActivity.this.getResources().getString(2131427500));
          localButton.setTextColor(StudyYDActivity.this.getResources().getColor(2131230728));
          localButton.setBackgroundDrawable(StudyYDActivity.this.getResources().getDrawable(2130837632));
          localButton.setEnabled(true);
        }
      }
    });
    this.lvList.setAdapter(this.adapter);
    this.lvList.setOnScrollListener(new AbsListView.OnScrollListener()
    {
      public void onScroll(AbsListView paramAnonymousAbsListView, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
      {
      }

      public void onScrollStateChanged(AbsListView paramAnonymousAbsListView, int paramAnonymousInt)
      {
        if ((paramAnonymousInt == 0) && (paramAnonymousAbsListView.getLastVisiblePosition() == -1 + paramAnonymousAbsListView.getCount()) && (!StudyYDActivity.this.lvList.getIsNoMore()) && (StudyYDActivity.this.blDataTask))
        {
          StudyYDActivity.this.lvList.prepareForRefreshMore();
          StudyYDActivity.this.isFoot = Boolean.valueOf(true);
          StudyYDActivity.this.loadingData(false);
        }
      }
    });
    this.lvList.setOnLoadMoreListener(new PageListView.OnRefreshListener()
    {
      public void onRefresh()
      {
        StudyYDActivity.this.lvList.prepareForRefreshMore();
        StudyYDActivity.this.isFoot = Boolean.valueOf(true);
        StudyYDActivity.this.loadingData(true);
      }
    });
    addOperation(new DataTask().execute(new String[] { "installindex" }));
  }

  private void loadingData(boolean paramBoolean)
  {
    if (paramBoolean)
      this.page.firstPage();
    while (true)
    {
      addOperation(new DataTask().execute(new String[] { "installindex" }));
      return;
      this.page.nextPage();
    }
  }

  private void removeEvent(String paramString)
  {
    if ((eventsDown != null) && (eventsDown.size() > 0));
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size())
        return;
      if (paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
      {
        eventsDown.remove(eventsDown.get(i));
        downAT.remove(paramString);
        return;
      }
    }
  }

  private void setCurrentProgressBar(String paramString, ProgressBar paramProgressBar, Button paramButton)
  {
    if ((eventsDown != null) && (eventsDown.size() > 0))
      for (int i = 0; ; i++)
      {
        if (i >= eventsDown.size());
        do
        {
          return;
          if (!paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
            break;
          paramProgressBar.setVisibility(0);
          paramButton.setText("取消");
        }
        while (paramProgressBar.getMax() >= ((AutoSoftInfo)eventsDown.get(i)).getMaxLVState());
        paramProgressBar.setMax(((AutoSoftInfo)eventsDown.get(i)).getMaxLVState());
        logInfo("pbjindunew:" + paramProgressBar.toString());
        ((DownloadAsyncTask)downAT.get(paramString)).setProgressBar(paramProgressBar);
        return;
        paramProgressBar.setVisibility(8);
      }
    paramProgressBar.setProgress(0);
    paramProgressBar.setVisibility(8);
  }

  private void setEventIsCancelDown(Boolean paramBoolean, String paramString)
  {
    if ((eventsDown != null) && (eventsDown.size() > 0));
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size())
        return;
      if (paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
      {
        ((AutoSoftInfo)eventsDown.get(i)).setIsCancelDownload(paramBoolean);
        return;
      }
    }
  }

  private void setEventLVState(int paramInt1, String paramString, int paramInt2)
  {
    if ((eventsDown != null) && (eventsDown.size() > 0));
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size());
      do
      {
        return;
        if (!paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
          break;
        ((AutoSoftInfo)eventsDown.get(i)).setLVState(paramInt1);
      }
      while (((AutoSoftInfo)eventsDown.get(i)).getMaxLVState() != 0);
      ((AutoSoftInfo)eventsDown.get(i)).setMaxLVState(paramInt2);
      return;
    }
  }

  private void showView(ProgressBar paramProgressBar, Button paramButton)
  {
    DownloadAsyncTask localDownloadAsyncTask = new DownloadAsyncTask();
    downAT.put(paramButton.getTag().toString(), localDownloadAsyncTask);
    localDownloadAsyncTask.execute(new View[] { paramProgressBar, paramButton });
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903150);
    isCancel = Boolean.valueOf(false);
    paused = Boolean.valueOf(false);
    this.typeID = getIntent().getStringExtra("TypeID");
    if ((this.typeID == null) || (this.typeID.length() == 0))
      this.typeID = "";
    initView();
  }

  protected void onResume()
  {
    super.onResume();
    if (this.adapter != null)
      this.adapter.notifyDataSetChanged();
  }

  class DataTask extends AsyncTask<String, Integer, String>
  {
    String param;

    DataTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.param = paramArrayOfString[0];
      if (this.param.equals("installindex"));
      try
      {
        StudyYDActivity.this.events = new LoadSourceForWeb(StudyYDActivity.this).getStudySource(StudyYDActivity.this.page.getPageNo(), StudyYDActivity.this.page.getPageSize());
        return null;
      }
      catch (Exception localException)
      {
        while (true)
          localException.printStackTrace();
      }
    }

    protected void onPostExecute(String paramString)
    {
      super.onPostExecute(paramString);
      if (this.param.equals("installindex"))
      {
        if ((StudyYDActivity.this.events == null) || (StudyYDActivity.this.events.size() <= 0))
          break label177;
        StudyYDActivity.this.page.addAllEntries(StudyYDActivity.this.events);
        StudyYDActivity.this.adapter.notifyDataSetChanged();
        StudyYDActivity.this.lvList.onLoadMoreComplete();
        if (StudyYDActivity.this.events.size() < StudyYDActivity.this.page.getPageSize())
        {
          StudyYDActivity.this.lvList.hideFotterMoreView();
          StudyYDActivity.this.lvList.setIsNoMore(true);
        }
        StudyYDActivity.this.events.clear();
      }
      while (true)
      {
        StudyYDActivity.this.blDataTask = true;
        if (!StudyYDActivity.this.isFoot.booleanValue())
        {
          StudyYDActivity.this.closeProgress();
          StudyYDActivity.this.isFoot = Boolean.valueOf(false);
        }
        return;
        label177: StudyYDActivity.this.lvList.hideFotterMoreView();
        StudyYDActivity.this.lvList.setIsNoMore(true);
      }
    }

    protected void onPreExecute()
    {
      super.onPreExecute();
      StudyYDActivity.this.blDataTask = false;
      if (!StudyYDActivity.this.isFoot.booleanValue())
        StudyYDActivity.this.showProgress("");
    }
  }

  class DownloadAsyncTask extends AsyncTask<View, Integer, Integer>
  {
    private Button btCurrent;
    private int fileSize;
    private String filename;
    private FileOutputStream fos;
    private InputStream is;
    private Boolean isCancelDownload = Boolean.valueOf(false);
    private String keyid;
    private ProgressBar pbCurrent;

    DownloadAsyncTask()
    {
    }

    protected Integer doInBackground(View[] paramArrayOfView)
    {
      this.pbCurrent = ((ProgressBar)paramArrayOfView[0]);
      this.btCurrent = ((Button)paramArrayOfView[1]);
      if (this.btCurrent.getTag() != null)
      {
        this.keyid = this.btCurrent.getTag().toString();
        this.filename = StudyYDActivity.this.apkpath.substring(1 + StudyYDActivity.this.apkpath.lastIndexOf("/"));
      }
      try
      {
        URL localURL = new URL(StudyYDActivity.this.apkpath);
        StudyYDActivity.this.logDebug("xjf downpath: " + Global.SOFTPATHSDCARD);
        URLConnection localURLConnection = localURL.openConnection();
        localURLConnection.connect();
        this.is = localURLConnection.getInputStream();
        this.fileSize = localURLConnection.getContentLength();
        this.pbCurrent.setMax(this.fileSize);
        if (this.fileSize <= 0)
          throw new RuntimeException(StudyYDActivity.this.getString(2131427562));
      }
      catch (Exception localException)
      {
        this.fileSize = -1;
        localException.printStackTrace();
        StudyYDActivity.this.logDebug("xjf" + localException.getMessage());
        return Integer.valueOf(this.fileSize);
        return Integer.valueOf(-100);
        if (this.is == null)
          throw new RuntimeException("stream is null");
      }
      finally
      {
        this.isCancelDownload = Boolean.valueOf(false);
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
      }
      label319: byte[] arrayOfByte;
      int i;
      if (Global.isSDCard())
      {
        this.fos = new FileOutputStream(Global.SOFTPATHSDCARD + this.filename);
        arrayOfByte = new byte[1024];
        i = 0;
        StudyYDActivity.this.logDebug("xjf fileSize:" + this.fileSize);
      }
      while (true)
      {
        boolean bool = this.isCancelDownload.booleanValue();
        if (bool);
        label546: int j;
        do
        {
          while (true)
          {
            this.isCancelDownload = Boolean.valueOf(false);
            com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
            break;
            this.fos = StudyYDActivity.this.openFileOutput(this.filename, 1);
            break label319;
            do
            {
              StudyYDActivity.this.logDebug("zhy paused:" + StudyYDActivity.paused.toString());
              Thread.sleep(500L);
            }
            while (StudyYDActivity.paused.booleanValue());
            StudyYDActivity.this.logDebug("zhy paused:" + StudyYDActivity.paused.toString());
            this.isCancelDownload = StudyYDActivity.this.getIsCancelDown(this.keyid);
            if ((!this.isCancelDownload.booleanValue()) && (!StudyYDActivity.isCancel.booleanValue()))
              break label546;
            StudyYDActivity.this.logDebug("zhy download Cancel: " + this.filename);
            this.fileSize = -2;
          }
          com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(0);
          j = this.is.read(arrayOfByte);
        }
        while (j == -1);
        this.fos.write(arrayOfByte, 0, j);
        i += j;
        Integer[] arrayOfInteger = new Integer[1];
        arrayOfInteger[0] = Integer.valueOf(i);
        publishProgress(arrayOfInteger);
      }
    }

    public String getKeyID()
    {
      return this.keyid;
    }

    protected void onPostExecute(Integer paramInteger)
    {
      if (StudyYDActivity.isCancel.booleanValue());
      do
      {
        return;
        this.pbCurrent.setProgress(0);
        this.pbCurrent.setVisibility(8);
      }
      while ((this.keyid == null) || (this.keyid.length() <= 0));
      StudyYDActivity.this.removeEvent(this.keyid);
      while (true)
      {
        try
        {
          Boolean localBoolean = Boolean.valueOf(Global.isSDCard());
          if (paramInteger.intValue() < 0)
            break label212;
          if (localBoolean.booleanValue())
          {
            if (paramInteger.intValue() != -1)
              Global.installApk(StudyYDActivity.this, Global.SOFTPATHSDCARD + this.filename);
            if (this.is != null)
              this.is.close();
            if (this.fos == null)
              break;
            this.fos.close();
            return;
          }
        }
        catch (Exception localException)
        {
          StudyYDActivity.this.logDebug("xjf error: " + localException.getMessage());
          return;
        }
        if (paramInteger.intValue() != -1)
        {
          Global.installApk(StudyYDActivity.this, Global.SOFTPATHMEMORY + this.filename);
          continue;
          label212: if (paramInteger.intValue() == -1)
            StudyYDActivity.this.alertMessage(StudyYDActivity.this.getString(2131428051));
        }
      }
    }

    protected void onPreExecute()
    {
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
      if (StudyYDActivity.isCancel.booleanValue());
      while ((this.keyid == null) || (this.keyid.length() <= 0))
        return;
      StudyYDActivity.this.setEventLVState(paramArrayOfInteger[0].intValue(), this.keyid, this.pbCurrent.getMax());
      StudyYDActivity.this.logInfo("pbjinduold:" + this.pbCurrent.toString());
      this.pbCurrent.setProgress(paramArrayOfInteger[0].intValue());
    }

    public void setProgressBar(ProgressBar paramProgressBar)
    {
      this.pbCurrent = paramProgressBar;
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.StudyYDActivity
 * JD-Core Version:    0.6.2
 */